package org.example.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

public class MyBatisXmlParser {
    public void parse() throws IOException {
        Document doc = Jsoup.parse(new File("/Users/xiaoktongxue/sanqistudy/three-phase-learning/maven/src/main/resources/mybatis.xml"), "utf-8");
        //返回一组数据
        Elements environments = doc.getElementsByTag("environments");
        if(environments.isEmpty()){
            return;
        }
        //返回一个元素
        Element element = environments.get(0);
        String aDefault = element.attr("default");
        Element environment = doc.getElementById(aDefault);
        Elements property = environment.getElementsByTag("property");
        for (Element element1 : property) {
            String name = element1.attr("name");
            String value = element1.attr("value");
            System.out.println(name+"="+value);
        }
    }
}
